import type { CartItem } from '@/types/cart'
import { http } from '@/utils/http'

// 加入购物车接口
export const postMemberCartAPI = (data: { skuId: string; count: number }) => {
  return http({
    method: 'POST',
    url: '/member/cart',
    data,
  })
}

// 会员中心-地址管理
// 获取收货地址列表
// GET
// /member/cart
export const getMembercartAPI = () => {
  return http<CartItem[]>({
    method: 'GET',
    url: '/member/cart',
  })
}

// 购物车
// 删除/清空购物车单品
// DELETE
// /member/cart
export const deleteMembercartAPI = (data: { ids: string[] }) => {
  return http({
    method: 'DELETE',
    url: '/member/cart',
    data,
  })
}

// 修改购物车单品
// PUT
// /member/cart/{skuId}

export const putMemberCartAPI = (skuId: string, data: { selected?: boolean; count?: number }) => {
  return http({
    method: 'PUT',
    url: `/member/cart/${skuId}`,
    data,
  })
}

// 购物车
// 购物车全选/取消全选
// PUT
// /member/cart/selected

export const putMemberCartSelectedData = (data: { selected: boolean }) => {
  return http({
    method: 'PUT',
    url: '/member/cart/selected',
    data,
  })
}
